package com.gitee.ago.clipboard.client;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.Objects;

public class ShareActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        Intent intent = getIntent();
        String action = intent.getAction();
        String type = intent.getType();

        if (Objects.equals(action, Intent.ACTION_SEND) && type != null) {
            Parcelable parcelableExtra = intent.getParcelableExtra(Intent.EXTRA_STREAM);
            Uri extra = (Uri) parcelableExtra;

            if ("video/".equals(type)) {
                // video/mp4

            }
        }

        if (Objects.equals(action, Intent.ACTION_SEND_MULTIPLE) && type != null) {
            ArrayList<Parcelable> parcelableArrayListExtra = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
            for (Parcelable parcelable : parcelableArrayListExtra) {
                
            }
        }
    }
}

/****************
 * intent = Intent { act=android.intent.action.SEND typ=video/mp4 flg=0x1b080001 cmp=com.gitee.ago.clipboard.client/.ShareActivity clip={video/mp4 {U(file)}} (has extras) }
 * action = android.intent.action.SEND
 * type = video/mp4
 * parcelableExtra = file:///storage/emulated/0/1/%E6%B7%B1%E5%BA%A6%E5%BD%95%E5%B1%8F_dde-desktop_20200428181647.mp4
 * extra = ...
 */

/****************
 * intent = Intent { act=android.intent.action.SEND_MULTIPLE typ=*\/* flg=0x1b080001 cmp=com.gitee.ago.clipboard.client/.ShareActivity clip={*\/* 2 items: {U(file)} {U(file)}} (has extras) }
 * action = android.intent.action.SEND_MULTIPLE
 * type = *\/*
 * parcelableArrayListExtra = size = 2
 * parcelable = file:///storage/emulated/0/1/%E6%B7%B1%E5%BA%A6%E5%BD%95%E5%B1%8F_dde-desktop_20200428181647.mp4
 * parcelable = file:///storage/emulated/0/1/05235401_HPOLSCDT_20201101135722066.pdf
 */